// File ProcessGenerator.java
// This class provides methods 
//   to decide whether there is any incoming new process within an unit time, 
//   and to generate a process with randomly chosen priority, processing time.


import java.util.*;


public class ProcessGenerator
{
    private double probability;
    private Random r;

    
    public ProcessGenerator(double value)
    {
	if ((value < 0) || (1 < value))
	    throw new IllegalArgumentException("Illegal probability: " + value);
	probability = value;
	r = new Random();
    }

    
    public boolean query()
    {
	return (r.nextDouble() < probability);
    }

    
    public Process getNewProcess(int arrivalTime, int maxProcessTime, int maxLevel)
    {
	int timeRemaining = r.nextInt(maxProcessTime) + 1;	
	int level = r.nextInt(maxLevel) + 1;
	Process p = new Process(arrivalTime, level, timeRemaining);
	return p;
    }
}
